package com.lipeng.api;

import com.lipeng.bean.Club;
import com.lipeng.bean.Master;
import com.lipeng.service.MasterService;
import com.lipeng.utils.AjaxResult;
import com.lipeng.utils.IPUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by dllo on 18/3/16.
 */
@Controller
@ResponseBody
@RequestMapping(value = "/api/")
public class MasterControllerAPI {
    @Resource
    private MasterService masterService;

    //大师列表
    @RequestMapping(value = "allmaster")
    public AjaxResult allMaster(){
        AjaxResult result = new AjaxResult();
        List<Master> masterList = masterService.selectAllMaster();
        if (masterList == null){
            result.setCode("0");
            result.setMessage("查询失败");
            return result;
        }
        for (Master master : masterList){
            master.setMpic(IPUtils.getIP()+":8080"+master.getMpic());
        }
        result.setCode("1");
        result.setMessage("查询成功");
        result.setData(masterList);
        return result;
    }

    //大师详情
    @RequestMapping(value = "masterdetail")
    public AjaxResult masterDetail(@RequestParam("mid")Integer mid){
        AjaxResult result = new AjaxResult();
        Master master = masterService.selectMasterById(mid);
        if (master == null){
            result.setCode("0");
            result.setMessage("查询失败");
            return result;
        }
        master.setMpic(IPUtils.getIP()+":8080"+master.getMpic());
        result.setCode("1");
        result.setMessage("查询成功");
        result.setData(master);
        return result;
    }

    //根据名称搜索
    @RequestMapping(value = "searchmastername")
    public AjaxResult searchname(@Param("name")String name){
        AjaxResult result = new AjaxResult();
        List<Master> masterList = masterService.selectMasterByName(name);

        if (masterList==null){
            result.setCode("0");
            result.setMessage("无相关信息");
            return result;
        }
        for (Master master : masterList){
            master.setMpic(IPUtils.getIP()+":8080"+master.getMpic());
        }
        result.setCode("1");
        result.setMessage("查询成功");
        result.setData(masterList);
        return result;
    }


}
